package com.feihong.yw189.activity;

import android.app.Activity;

import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * Created by PVer on 2018/2/11.
 */

public class MyActivityManager {

    public static Stack<SoftReference<Activity>> mActivites = new Stack<SoftReference<Activity>>();

    public static void addActivity(Activity act) { //将activity的实例放入list中进行维护
        SoftReference<Activity> softReference = new SoftReference<Activity>(act);
        mActivites.add(softReference);
    }

    public static void removeActivity(Activity act) {
        mActivites.remove(act);//将已经销毁的activity在list中清除，与实际的activity活动个数保持.一致
    }

    public static void finishAll() {
        for (SoftReference softReference : mActivites) {
            if(softReference != null){
                Activity activity = (Activity) softReference.get();
                if(activity != null && !activity.isFinishing() && !activity.isDestroyed()){
                    activity.finish();
                }
            }
        }
    }
}
